package summer.hot100.v1;

import java.util.LinkedList;
import java.util.List;

public class Solution494 {
    public int findTargetSumWays(int[] nums, int target) {
        int sum = 0;
        for (int x : nums) {
            sum += x;
        }
        sum += target;
        if (sum % 2 != 0) return 0;
        if (sum < 0) return 0;
        int n = sum >> 1;
        int[] dp = new int[n + 1];
        dp[0] = 1;
        for (int i = 0; i < nums.length; i++) {
            for (int j = n; j >= nums[i]; j--) {
                dp[j] += dp[j - nums[i]];
            }
        }
        return dp[n];
    }
}
